package com.emergency.db.controller.staff;

import com.emergency.common.entity.Result;
import com.emergency.common.entity.StatusCode;
import com.emergency.db.domain.staff.StaffStatus;
import com.emergency.db.service.staff.StaffStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/staff/status")
@CrossOrigin
public class StaffStatusController {
    @Autowired
    private StaffStatusService staffStatusService;

    //保存
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(@RequestBody StaffStatus staffStatus) {
        Long id = staffStatusService.save(staffStatus);
        return new Result(true, StatusCode.OK, "保存成功", id);
    }

    //查询单项
    @RequestMapping(value = "/search/{id}", method = RequestMethod.POST)
    public Result findById(@PathVariable("id") Long id) {
        StaffStatus staffStatus = staffStatusService.findById(id);
        return new Result(true, StatusCode.OK, "查询成功", staffStatus);
    }

    //根据staff_id 查询
    @RequestMapping(value = "/search/staff/{id}", method = RequestMethod.POST)
    public Result findByStaff(@PathVariable("id") Long id) {
        List<StaffStatus> staffStatusList = staffStatusService.findAllByStaff(id);
        return new Result(true, StatusCode.OK, "查询成功", staffStatusList);
    }

    //删除
    @RequestMapping(value = "/del/{id}", method = RequestMethod.POST)
    public Result delete(@PathVariable Long id) {
        staffStatusService.delete(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    //删除ByStaff
    @RequestMapping(value = "/del/staff/{id}", method = RequestMethod.POST)
    public Result deleteAllByStaff(@PathVariable Long id) {
        staffStatusService.deleteAllByStaff(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    @RequestMapping(value = "list/{page}/{size}", method = RequestMethod.POST)
    public Result list(@RequestBody Map searchMap, @PathVariable int page, @PathVariable int size) {
        Page<StaffStatus> pageList = staffStatusService.findList(searchMap, page, size);
        return new Result(true, StatusCode.OK, "操作成功", pageList);
    }
}
